home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5069 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.0 KB

  1. Path: news.uni-jena.de!news
  2. From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: External access to private class variables
  5. Date: 2 Feb 1996 11:51:11 GMT
  6. Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
  7. Message-ID: <4estrf$80l@fsuj01.rz.uni-jena.de>
  8. References: <4ermr9$ii7@cloner2.ix.netcom.com>
  9. Reply-To: mkt@isun04.inf.uni-jena.de
  10. NNTP-Posting-Host: isun07.inf.uni-jena.de
  11.  
  12. > class X 
  13. > {
  14. > private:
  15. >     int value;
  16. > public:
  17. >     X (int n = 0) { value = n; }
  18. >     int& GSValue () { return value; }   // return a reference to the 
  19. >                                         // private member "value"
  20. > };
  21.  
  22. Of course you can return a handle to a private member.
  23. The member function is authorized to do so! It can access the
  24. private member and so can do anything it wants to do with it
  25. (inclusive building handles to the data and post the handles anywhere).
  26.  
  27. This is a known problem! The books always say: "Never pass
  28. a handle to private data/functions to the outside" (or something
  29. like this).
  30.  
  31.